home *** CD-ROM | disk | FTP | other *** search
- /****************************/
- /* HyperUtils.c */
- /* */
- /* A collection of useful */
- /* routines... */
- /* */
- /****************************/
- #include <MacTypes.h>
- #include <OSUtil.h>
- #include <MemoryMgr.h>
- #include <FileMgr.h>
- #include <ResourceMgr.h>
- #include <StdFilePkg.h>
- #include "HyperXCmd.h"
- #include "HyperUtils.h"
-
- void CenterWindow( wptr )
- WindowPtr wptr;
- /***************************
- * Center a window in the current
- * screen port. Note: Does not
- * attempt to work with multi-screen
- * systems.
- *
- * This code is inspired by a
- * similar routine written by Steve
- * Maller in MPW Pascal. Thanks Steve.
- ***************************/
- {
- short hWindSize = wptr->portRect.right - wptr->portRect.left;
- short vWindSize = wptr->portRect.bottom - wptr->portRect.top;
- short hSize = wptr->portBits.bounds.right - wptr->portBits.bounds.left;
- short vSize = wptr->portBits.bounds.bottom - wptr->portBits.bounds.top;
-
- MoveWindow( wptr,
- ( hSize - hWindSize ) / 2,
- ( vSize - vWindSize + 20) / 2,
- false
- );
- }
-
- void Concat( str1, str2 )
- char *str1;
- char *str2;
- /*****************************
- * Append string 2 to the end of
- * string 1. Both strings are
- * pascal-format strings.
- *
- * str1 must be large enough to hold
- * the new string and is assumed to
- * be of Type Str255 (a pascal string)
- *****************************/
- {
- short len1 = *str1; /*** the number of chars in string 1 ***/
- short len2 = *str2++; /*** the number of chars in string 2 ***/
- char *temp; /*** string pointer ***/
-
- if( len1 +len2 > 255 )
- len2 = 255 - len1;
-
- *str1++ += len2 ; /*** add sizes together to get new size ***/
-
- temp = str1 + len1; /*** move to the end of string 1 ***/
- while( len2 ){
- *temp++ = *str2++; /*** add a char to temp and move along ***/
- --len2; /*** until all characters are added ***/
- }
-
- }
-
- void CopyPStr( pStr1, pStr2 )
- char *pStr1;
- char *pStr2;
- /****************************
- * Copy the contents of pstr1 into
- * pstr2. The strings are assumed
- * to be of type STR255 (length byte
- * precedes data
- *
- ****************************/
- { short i;
- char *tstr;
-
- tstr = pStr2;
-
- for( i = 0; i <= *pStr1; i++ )
- *tstr++ = *pStr1++;
- }
-
-
- short GetFileNameToOpen( typs, typCnt,theName, theWDID )
- SFTypeList typs;
- short typCnt;
- char *theName;
- short *theWDID;
- /*****************************
- * Invokes SFOpenFile to query the
- * user for the name of a file to
- * open.
- *
- * In: List of types of files to
- * filter for (up to 4)
- *
- * Out: fileName if picked in theName
- * working directory in theWDID
- * nil otherwise
- * the file's volum ref num.
- *
- * ( Note that the space for the
- * string must be allocated by the
- * caller).
- *****************************/
- {
- Point where;
- char prompt[1];
- SFReply reply;
- GrafPort *oldPort;
- WindowPtr dlogID;
-
- prompt[0] = '\0';
-
- /*** Get and put up the standard file ***/
- /*** dialog. You will only see the file***/
- /*** types that you filtered for. If ***/
- /*** you filtered for no files, then ***/
- /*** all files will display ***/
-
- GetPort( &oldPort );
- dlogID = GetNewDialog( (short)getDlgID, (Ptr)NIL, (Ptr)UPFRONT );
-
- SetPort( dlogID );
- CenterWindow( dlogID );
- where.h = dlogID->portRect.left;
- where.v = dlogID->portRect.top;
- LocalToGlobal( &where );
-
- SFGetFile( where, prompt, (Ptr)NIL, typCnt, typs, (Ptr)NIL, &reply );
-
- DisposDialog( dlogID );
- SetPort( oldPort );
-
- /*** If the user selected a file, let's ***/
- /*** get the information about it ***/
-
- if (reply.good){
- *theWDID = reply.vRefNum;
- PtoCstr( (char *)&reply.fName );
- strcpy( theName, &reply.fName );
- }
- return( reply.good );
- }
-